home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_069 / wc / poster next >
Text File  |  1992-05-06  |  3KB  |  73 lines

  1. Article 829 of net.sources:
  2. Path: mcdsun!noao!hao!nbires!seismo!rutgers!ll-xn!mit-eddie!uw-beaver!tektronix!teklds!copper!stevesu
  3. From: stevesu@copper.TEK.COM (Steve Summit)
  4. Newsgroups: net.sources
  5. Subject: Fast wc
  6. Message-ID: <970@copper.TEK.COM>
  7. Date: 11 Apr 87 02:18:38 GMT
  8. Reply-To: stevesu@copper.UUCP (Steve Summit)
  9. Distribution: world
  10. Organization: Tektronix, Inc., Beaverton, OR.
  11. Lines: 462
  12.  
  13. Here's something I came across in my bin directory.  According to
  14. the modification time on the file, I must have written it back in
  15. 1984.  It's just like the "standard" wc (4.[23]bsd, anyway) with
  16. the following two improvements:
  17.  
  18.      1.    It doesn't count what you don't ask for.  Therefore,
  19.     wc -l is faster and wc -c is _m_u_c_h faster than when it has
  20.     to count words (which is harder).  It also seems to be
  21.     considerably faster than /usr/ucb/wc.
  22.  
  23.      2. It has the -v (verbose) and -p (count pages) options that
  24.     some old version of wc (4.1? 2.9?) that I got used to had.
  25.  
  26.      3.    (Three! Three improvements! _N_obody expects...) It prints
  27.     the fields in the order you ask for (i.e. wc -cwl gives
  28.     you the reverse of the usual order).  (This isn't
  29.     terribly important, and I've never made use of it, but
  30.     for some reason I wrote it that way.)
  31.  
  32. There is also a -s flag that lets you set the page size used in
  33. calculating page counts with -p.
  34.  
  35. Here is a timing comparison (on a 780 running Ultrix):
  36.  
  37.     $ cd /usr/dict
  38.     $ time /usr/ucb/wc words web*
  39.        24259   24259  198596 words
  40.       234936  234936 2486813 web2
  41.        76205  121847 1012730 web2a
  42.       335400  381042 3698139 total
  43.           3:29.2 real        56.9 user        10.8 sys
  44.  
  45.     $ time wc.new words web* > /dev/null
  46.           1:44.1 real        26.7 user        11.7 sys
  47.  
  48.     $ time wc.new -w words web* > /dev/null
  49.           1:50.0 real        26.1 user        11.9 sys
  50.  
  51.     $ time wc.new -l words web* > /dev/null
  52.           1:08.5 real        14.6 user        11.4 sys
  53.  
  54.     $ time wc.new -c words web* > /dev/null
  55.             25.8 real         0.2 user         9.7 sys
  56.  
  57. Of course, if all you really care about is the character count,
  58. an ls -l is faster still (although it will give you a different
  59. answer if the file contains bad blocks, but I digress).
  60.  
  61. The word-counting algorithm probably isn't the one I would have
  62. chosen, but it matches the one that /usr/ucb/wc uses.
  63.  
  64. If you're picky about plug compatibility, you should note that
  65. the error handling is a bit different than the standard version.
  66. (There is, regrettably, no "usage:" message.)
  67.  
  68. Following my signature are the source and man page.
  69.  
  70.                                            Steve Summit
  71.                                            stevesu@copper.tek.com
  72.  
  73.